package com.lyk.read.book.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.lyk.common.base.BaseDialog

/**
 * Created by LianYongKe on 2024/4/5.
 */
abstract class BaseBindingDialog<T : ViewBinding> : BaseDialog() {

    lateinit var binding: T

    open fun getDialogWidth():Int = -1

    open fun getDialogHeight():Int = -1

    override fun onStart() {
        val width = getDialogWidth()
        val height = getDialogHeight()
        isStart = width != -1 || height != -1

        super.onStart()

        if (isStart) {
            val window = dialog?.window
            window?.setLayout(
                if (width == -1) window.attributes.height else width,
                if (height == -1) window.attributes.height else height
            )
        }
    }

    abstract fun getBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): T

    abstract fun initView()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = getBinding(inflater, container)
        initView()
        return binding.root
    }

    override fun getContentView(): Int = 0

    override fun initView(view: View) {
    }
}